<?php

namespace App\Admin\Controllers;

use App\Income;
use App\Http\Controllers\Controller;
use Encore\Admin\Controllers\HasResourceActions;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Layout\Content;
use Encore\Admin\Show;
use Encore\Admin\Widgets\Box;

class IncomeController extends Controller
{
    use HasResourceActions;

    /**
     * Index interface.
     *
     * @param Content $content
     * @return Content
     */
    public function index(Content $content)
    {

        $data = [1, 2, 3, 4];
        return $content
            ->header('收入管理')
            ->description('列表')
            ->body($this->grid());
          /*  ->body(new Box('饼图', view('admin.income.pie', compact('data'))));*/

    }

    /**
     * Show interface.
     *
     * @param mixed $id
     * @param Content $content
     * @return Content
     */
    public function show($id, Content $content)
    {
        return $content
            ->header('收入管理')
            ->description('详情')
            ->body($this->detail($id));
    }

    /**
     * Edit interface.
     *
     * @param mixed $id
     * @param Content $content
     * @return Content
     */
    public function edit($id, Content $content)
    {
        return $content
            ->header('收入管理')
            ->description('编辑')
            ->body($this->form()->edit($id));
    }

    /**
     * Create interface.
     *
     * @param Content $content
     * @return Content
     */
    public function create(Content $content)
    {
        return $content
            ->header('收入管理')
            ->description('新增')
            ->body($this->form());
    }

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new Income);
        $grid->id('ID');
        $grid->user()->name('用户');
        $grid->user()->type('用户类型')->using(['0'=>'个人','1'=>'公司','2'=>'代理','3'=>'生产厂商','4'=>'合作厂商','5'=>'投资方']);
        $grid->fee('收益金额');
        $grid->order()->order_sn('订单号');
        $grid->order()->pay_price('订单金额');
        $grid->created_at('新增时间');
        $grid->updated_at('编辑时间');
        $grid->disableCreateButton();
        $grid->actions(function ($actions) {
            $actions->disableView();
            $actions->disableEdit();
        });

        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(Income::findOrFail($id));

        $show->id('ID');
        $show->created_at('新增时间');
        $show->updated_at('编辑时间');

        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new Income);

        $form->display('ID');
        $form->display('新增时间');
        $form->display('变价时间');

        return $form;
    }
}
